﻿Imports System.Xml

Namespace Stories
	Public Class CharacterStyleRange
		Inherits Child

		Public Sub New()
			Children = New List(Of Child)
		End Sub

		Property AppliedCharacterStyle As String

		Property FillColor As String

		Property FontStyle As String

		Property PointSize As String

		Property AppliedFont As String

		Property Leading As String

		Property Children As List(Of Child)

		Shared Function ReadXml(reader As XmlReader) As CharacterStyleRange
			Dim csr As New CharacterStyleRange()

			If reader.HasAttributes Then
				csr.AppliedCharacterStyle = reader.GetAttribute("AppliedCharacterStyle")
				csr.FillColor = reader.GetAttribute("FillColor")
				csr.FontStyle = reader.GetAttribute("FontStyle")
				csr.PointSize = reader.GetAttribute("PointSize")
			End If

			While reader.Read()
				Select Case reader.Name
					Case "Properties"
						While reader.Read()
							Select Case reader.Name
								Case "Leading"
									csr.Leading = reader.ReadString()
								Case "AppliedFont"
									csr.AppliedFont = reader.ReadString()
								Case "Properties"
									If reader.NodeType = XmlNodeType.EndElement Then Exit While
								Case Else
									Debug.WriteLine("Unrecognized element: {0} in element: {1}", reader.Name, "CharacterStyleRange -> Properties")
							End Select
						End While
					Case "Footnote"
						csr.Children.Add(Footnote.ReadXml(reader))
					Case "GaijiOwnedItemObject"
						csr.Children.Add(GaijiOwnedItemObject.ReadXml(reader))
					Case "Note"
						csr.Children.Add(Note.ReadNote(reader))
					Case "Table"
						csr.Children.Add(Table.ReadXml(reader))
					Case "TextVariableInstance"
						csr.Children.Add(TextVariableInstance.ReadXml(reader))
						'add more cases here
					Case "XMLElement"
						csr.Children.Add(XmlElement.ReadXml(reader))
					Case "HiddenText"
						csr.Children.Add(HiddenText.ReadXml(reader))
					Case "Content"
						csr.Children.Add(New Content(reader.ReadString()))
					Case "Br"
						csr.Children.Add(New Br())
					Case "CharacterStyleRange"
						If reader.NodeType = XmlNodeType.EndElement Then Exit While
					Case Else
						Debug.WriteLine("Unrecognized element: {0} in element: {1}", reader.Name, "CharacterStyleRange")
				End Select
			End While

			Return csr
		End Function

	End Class
End Namespace